package com.lz.football.module.wineBar.view
{
	import com.common.stdlib.DateUtil;
	import com.common.utils.Reflection;
	import com.common.utils.timeUtils.TimerManager;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.events.WinebarEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.type.BuildingType;
	import com.liangzhong.model.winebar.vo.WineBarInfoVo;
	import com.lz.football.module.wineBar.IWineBarView;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.text.TextField;
	
	import lz.controls.Alert;
	import lz.controls.BaseWindow;
	import lz.controls.core.TitleWindow;
	import lz.controls.core.UIComponent;
	import lz.controls.managers.PopUpManager;

	/**
	 *酒吧 
	 * @author lake
	 * 
	 */	
	public class WineBarView extends TitleWindow implements IWineBarView
	{
		/**
		 *背景 
		 */		
		private var bgMc 				:MovieClip;
		/**
		 * 离开按钮
		 */		
		private var leaveBtn			:SimpleButton;
		/**
		 * 经验信息
		 */		
		private var expInfoMc			:MovieClip;
		/**
		 *经验面板 
		 */		
		private var expPanel			:ExpPanel;
		
		public function WineBarView()
		{
			super();
		}
		/**
		 *获取背景 
		 * @return 
		 * 
		 */		
		public function get bg():DisplayObject
		{
			if(bgMc == null)
			{
				bgMc = Reflection.createInstance("com.football.winebar.view.BgSkin");
			}
			return bgMc;
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.football.winebar.view.WineBarSkin");
			if(_symbolSkin == null)
			{
				return;
			}
			this.addChild(_symbolSkin);
			leaveBtn 		= _symbolSkin.leaveBtn;
			expInfoMc 		= _symbolSkin.expInfoMc;
			//设置关闭按钮
			setCloseBtn(leaveBtn);
			//自适应
			resizeEnabled = true;
			//调整UI
			resize();
			//浅入
			fadeIn();
			//显示信息
			showBaseInfo();
			//经验面板
			expPanel = new ExpPanel();
			expPanel.initUI(expInfoMc);
			//添加事件
			addEvtListener();
		}
		/**
		 *浅入 
		 * 
		 */		
		override public function fadeIn():void
		{
			_symbolSkin.alpha = .3;
			TweenLite.to(_symbolSkin,fadeInDuration,{alpha:1});
			bg.alpha = .5;
			TweenLite.to(bg,.3,{alpha:1});
		}
		/**
		 *显示基本信息
		 * 
		 */		
		private function showBaseInfo():void
		{
			
		}
		/**
		 * 
		 * 添加事件
		 */		
		public function addEvtListener():void
		{
			AppData.getInstance().winebarManager.addEventListener(Event.CHANGE,dataChangeHandler);
		}
		/**
		 *数据改变 
		 * @param e
		 */		
		private function dataChangeHandler(e :Event):void
		{
			showBaseInfo();
		}
		/**
		 *自适应 
		 * @param e
		 * 
		 */		
		override protected function onResizeHandler(e:Event):void
		{
			resize();
		}
		/**
		 *大小重置 
		 */		
		private function resize():void
		{
			leaveBtn.x = GlobalDef.GameStage.stageWidth - leaveBtn.width;
			expInfoMc.x = GlobalDef.GameStage.stageWidth - expInfoMc.width - 20;
			expInfoMc.y = GlobalDef.GameStage.stageHeight - expInfoMc.height - 20;
			if(bgMc.parent)
			{
				bgMc.parent.x = ( GlobalDef.GameStage.stageWidth - bgMc.width)/2;
				bgMc.parent.y = ( GlobalDef.GameStage.stageHeight - bgMc.height)/2;
				if((Math.abs(bgMc.parent.x) + GlobalDef.GameStage.stageWidth)>bgMc.parent.width)
				{
					bgMc.parent.x = GlobalDef.GameStage.stageWidth - bgMc.parent.width;
				}
				if((Math.abs(bgMc.parent.y) + GlobalDef.GameStage.stageHeight)>bgMc.parent.height)
				{
					bgMc.parent.y = GlobalDef.GameStage.stageHeight - bgMc.parent.height;
				}
			}
		}
		/**
		 *点击升级 
		 * @param e
		 * 
		 */		
		private function gradeClickHandler(e :MouseEvent):void
		{
			this.dispatchEvent(new WinebarEvent(WinebarEvent.GRADE_UP));
		}
		/**
		 * 
		 * 删除事件
		 */		
		public function removeEvtListener():void
		{
			AppData.getInstance().winebarManager.removeEventListener(Event.CHANGE,dataChangeHandler);
		}
		/**
		 * 关闭按钮响应
		 * @param e
		 * 
		 */		
		override protected function onCloseHandler(e :MouseEvent):void
		{
			var info :String = "您确定离开酒吧吗?";
			//Alert.show(info,"",Alert.YES | Alert.NO,GlobalDef.AlertContainer,closeAlertHandler);
			closeAlertHandler(Alert.YES);
		}
		/**
		 *离开确认 
		 * @param type
		 * 
		 */		
		private function closeAlertHandler(type :int):void
		{
			if(Alert.YES == type)
			{
				_symbolSkin.mouseEnabled = false;
				_symbolSkin.mouseChildren = false;
				this.dispatchEvent(new WinebarEvent(WinebarEvent.LEAVE));
				this.dispatchEvent(new ModuleEvent(ModuleEvent.REMOVE_MODULE,true));
				super.onCloseHandler(null);
			}
		}
		/**
		 * 销毁
		 * 
		 */		
		public function destroyView():void
		{
			removeEvtListener();
			resizeEnabled = false;
			expPanel.destroyView();
			expPanel = null;
		}
		/**
		 * 选择类型tab显示
		 * @param $obj
		 * 
		 */		
		public function showType($obj:Object):void
		{
		}
		//////////////////////implements///////////////////////////
		/**
		 *升级 
		 */		
		public function gradeUp():void
		{
			showBaseInfo();
		}
		/**
		 *去除时间 
		 * 
		 */		
		public function dropTime():void
		{
			showBaseInfo();
		}
		/**
		 * 离开结果 
		 * @param obj
		 */		
		public function leaveRes(obj:Object):void
		{
			
		}
	}
}